<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
		








<link rel="stylesheet" type="text/css" href="/cbweb/jsp/resource/css/default.css">
<link rel="stylesheet" type="text/css" href="/cbweb/resource/css/public.css">
<link rel="stylesheet" type="text/css" href="/cbweb/resource/css/ddspstyle.css">
<link rel="stylesheet" type="text/css" href="/cbweb/plug-in/jquery/easyui/themes/default/easyui.css" id="easyuiTheme">
<link rel="stylesheet" type="text/css" href="/cbweb/plug-in/jquery/easyui/themes/icon.css">

<script type="text/javascript" src="/cbweb/plug-in/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/cbweb/resource/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="/cbweb/plug-in/jquery/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/cbweb/plug-in/jquery/easyui/locale/easyui-lang-zh_CN.js"></script>

<script type="text/javascript" src="/cbweb/resource/common/js/extEasyUI.js"></script>
<script type="text/javascript" src="/cbweb/resource/common/js/ajaxInterceptor.js"></script>

<script type="text/javascript" src="/cbweb/plug-in/My97DatePicker/WdatePicker.js"></script>

<script type="text/javascript" src="/cbweb/plug-in/jquery/validate/formValidator.js"></script>
<script type="text/javascript" src="/cbweb/plug-in/jquery/validate/formValidatorRegex.js"></script>

<!--<script type="text/javascript" src="/cbweb/resource/plugin/kindeditor/kindeditor-min.js"></script>-->

<script type="text/javascript" src="/cbweb/resource/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/cbweb/resource/js/ueditor/ueditor.all.min.js"></script>
<!--<link  href="/cbweb/resource/js/ueditor/themes/default/css/ueditor.css" rel="stylesheet" type="text/css"/>-->
<!--<script type="text/javascript" src="/cbweb/resource/js/ueditor/lang/zh-cn/zh-cn.js"></script>-->
<script type="text/javascript" src="/cbweb/resource/js/app.js"></script>




<script type="text/javascript">
document.onkeydown=function(event){
            var e = event || window.event || arguments.callee.caller.arguments[0];
             if(e && e.keyCode==13){ // enter 键
             try { 
                  searchData();
                  } catch (e) { 
                  gotoSearch($('#easyui-treegrid'));
            	}
            }
        }; 
        
        </script>
			<script type="text/javascript"
	src="/cbweb/resource/js/webuploader/webuploader.js"></script>
<link rel="stylesheet" type="text/css"
	href="/cbweb/resource/js/webuploader/webuploader.css" />
<link rel="stylesheet" type="text/css"
	href="/cbweb/resource/js/webuploader/style.css" />
		<title>添加直播视频 </title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<script type="text/javascript">
		
			$(function() {
				$.formValidator.initConfig({formID: 'contentForm', mode: 'AutoTip', errorFocus: true});

				$('#tmpid').formValidator({onShow: '', onFocus: '请选择所属行业用户'}).inputValidator({max: 100});
				$('#name').formValidator({onShow: '', onFocus: '长度最多100字节'}).inputValidator({max: 100});
			
	
			
			});
			function _resetFm(){
			 
			  	$('#epgName').val('');
			  	$('#tmpid').val('');
			  	$('#name').val('');
			  
			}
			  
			function _submitFm(){
			  
          
         
			  // var fname = fx.GetFileName(0);
			  //if(fname=="" || fname ==null) { $.messager.alert('提示', '上传失败，请从新上传', 'warning');return false;};
			   //$("#filepath").val(fname);
			   
			   $.ajax({
				async: false,
				url :'/cbweb/vchannel/addmedia.html',
				type:'post',
				data:$("#contentForm").serialize(),
				dataType:"JSON",
				success:function(data){
				//alert(data.success);
				
						if(data.success){
								$.messager.progress('close');
									$.messager.alert('提示', '提交成功！', 'info', function() {
										parent.$('#dlg').dialog('close');	
										parent.gotoSearch($('#easyui-treegrid'));
									});
								}else {
									alert("提交失败！");
								}
					},
					error:function(data){
						alert("提交失败，请联系管理员！");
					}
			});
			
			  /**
				$('#contentForm').form('submit', {
	            	onSubmit: function(param) {
						param.iframe = true; // 设置iframe提交标记
						var isValid = $.formValidator.pageIsValid();
						
						if (isValid) {
							$.messager.progress({
			                	text: '正在提交，请稍候....'
				            });
						}
	                    return isValid;
	                },
	                success: function(result) {
               			if($.parseJSON(result).success==false){
               				$.messager.alert('提示', $.parseJSON(result).msg, 'info', function() {
               					$.messager.progress('close');
								//parent.$('#dlg').dialog('close');	
								//parent.gotoSearch($('#easyui-treegrid'));
							});
               			}else{
		               		if (checkAjaxRequestValidity(result)) {
								$.messager.progress('close');
								$.messager.alert('提示', '提交成功！', 'info', function() {
									parent.$('#dlg').dialog('close');	
									parent.gotoSearch($('#easyui-treegrid'));
								});
		               		}
               			}
	                }
	                
	            });
	            **/
			}
			
			
			function openselect(){			
				openDialog($('#openselect'),'/cbweb/openselect/templates.html?vchannelFlag=vchannel');
		}
		
		
        	function onpress(){
				var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
   		  		if (event.keyCode == 13){  
      				gotoSearch($('#easyui-treegrid'));
    			}
		}
		
      
		
		</script>
	</head>

	<body class="overfwidth">
		<div class="barnavtop">
			您所在的位置：直播视频管理 &gt; 添加视频
		</div>
		<div id="workspace">
			<!--主体 开始-->
			<div id="container">
				<div class="editspace" >
					<form id="contentForm" action="" class="cmxform" method="post" name="formName">
		          	<input id="id" name="id" value="" class="yl_inp yw_name"  type="hidden"/>
		            <legend>直播视频新增</legend>
			           <fieldset>
             			<div class="fitem">
             			<table width="100%" border="0" cellpadding="0" cellspacing="0">
			           		<tr>
			           			<td width="20%" align="right">
		 							所属行业客户：
			                   	</td>
			                   	<td><input name="userName" id="epgName" style="width: 150px;" onkeydown="onpress();" value="114新零售" class="yl_inp yw_name"/>
			  					   <input name="tmpid" id="tmpid" style="width: 150px;" type="hidden" value="12389" class="yl_inp yw_name"/>
			 			         <a  class="easyui-linkbutton" data-options="iconCls:'icon-search', plain:true" onclick="openselect()"  href="javascript:void(0)">请选择</a>
			 			         <span id="tmpidTip" class="tip"></span>
			 			         </td>
			                </tr>
			                </table>
			               </div>
			            </fieldset>    
			        	
						
			        	<fieldset>
             			<div class="fitem">
             			<table width="100%" border="0" cellpadding="0" cellspacing="0">
			           		<tr>
			           			<td width="20%" align="right">
		 							视频名称：
			                   	</td>
			                   	<td >
		      						<input name="name" id="name" style="width: 150px;" onkeydown="onpress();" value="" class="yl_inp yw_name"/>
		      						<span id="nameTip" class="tip"></span>
			                   	</td>
			                </tr>
			                </table></div>
			            </fieldset> 
			            
			            
			            
			            
			            
			            
			            <!-- 
			            <fieldset>
             			<div class="fitem">
             			<table width="100%" border="0" cellpadding="0" cellspacing="0">
			           		<tr>
			           			<td width="20%" align="right">
		      						文件夹路径：
			                   	</td>
			                 
		 							<td > 
		 							<input id="path" type="text" style="width:260px;" name="path" class="yl_inp yw_name">
		 							<input type="button" onclick="setPath();" value="设置路径">
                                              <span style="color:Red;">上传以后设置无效</span>
                                         <br/>      
		 							
		      						
		      	<object id="FtpX" width="600" height="45" codebase="/cbweb/plug-in/cab/FtpX.cab#version=1,0,0,5"  
                    classid="CLSID:70DBB3DD-3DC3-4D45-8564-56777B4C46BB">
                    <param name="_Version" value="65536" />
                    <param name="_ExtentX" value="12806"/>
                    <param name="_ExtentY" value="1747"/>
                    <param name="_StockProps" value="0"/>
                </object>
                <input id="filepath" type="hidden" style="width:260px;" name="filepath" class="yl_inp yw_name">
					
			
		      						
		      						<span id="statusTip" class="tip"></span>
			                   	</td>
	      							
			                   	
			                </tr>
			                </table></div>
			            </fieldset>
			             -->
			             
			       <fieldset>
								<div class="fitem">
									<table width="100%" border="0" cellpadding="0" cellspacing="0">
										<tr>
											<td width="20%" align="right">上传文件：
											<input id="filepath" type="hidden" style="width:260px;" name="filepath" class="yl_inp yw_name">
												<input type="hidden" name="filePath_2" id="filePath_2" />
												<input type="hidden" name="purl" id="purl" />
												<input type="hidden" name="puser" id="puser" />
												<input type="hidden" name="ppsw" id="ppsw" />
												  </td>
											<td width="80%">
											<!-- 
											<div id="uploader">
														<input type="file" name="file_upload" id="file_upload" />
													<span style="font-weight: bold;">
														<a href="javascript:myUploadMethod()">上传</a>&nbsp;
														<a href="javascript:$('#file_upload').uploadify('stop')">取消上传</a>
														<a id="tipContent" href="#"  style="display:none;color:red;"></a>
													</span>
													<div id="uploader_queue"></div>
													<div id="uploader_view"></div>
													<div id="completeFileName"></div>
											 -->
										<div style="margin: 20px 20px 20px 0;">
											<div id="picker" class="form-control-focus">选择文件</div>
										</div> 
										<div id="thelist" class="uploader-list"></div>
										
										<div id="progresss" class="progress" style="width: 420px;display: none">
											<div id="progress" class="progress-bar"
												style="width: 10%; background: #f0ad4e">
												<span>10%</span>
											</div>
										</div>
										<input id="path" type="text" style="display: none" name="path" class="yl_inp yw_name">
										 <span id="statusTip"
										class="tip"></span>

												</div>
											</td>
										</tr>
									</table>
								</div>
							</fieldset> 
			              
			            
		          	</form>
		      </div>
              <div class="toolbar" style="text-align: center;"> 
              <a id="submitA" class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(auto_upload())" ><span><span>上传并保存</span></span></a> 
              <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:parent.$('#dlg').dialog('close')">取消</a>
              </div>
			</div>
			<!--主体 结束-->
		</div>



	<div id="openselect" class="easyui-dialog" style="width:550px;height:430px;padding-top: 0px;"
    	 data-options="title: '行业客户', iconCls:'icon-save',modal:true,closed:true,buttons:'#openselect_buttons'">
   		<iframe scrolling="auto" frameborder="0" style="width:100%;height:99%;"></iframe>
    </div>
    <div id="openselect_buttons" style="display: none;text-align: center;">
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:gotoconfButton()">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#openselect').dialog('close')">取消</a>
    </div>
    
    	<script type="text/javascript">
    	
    	var date = new Date();
    	var y = date.getFullYear();
    	var M = date.getMonth() + 1;
    	if (M >= 1 && M <= 9) {
    		M = "0" + M;
    	}
    	var d = date.getDate();
    	if (d >= 1 && d <= 9) {
    		d = "0" + d;
    	}
    	var H = date.getHours();
    	if (H >= 1 && H <= 9) {
    		H = "0" + H;
    	}
    	var m = date.getMinutes();
    	if (m >= 1 && m <= 9) {
    		m = "0" + m;
    	}
    	var s = date.getSeconds();
    	if (s >= 1 && s <= 9) {
    		s = "0" + s;
    	}
    	var ms = date.getMilliseconds();

    	if (ms >= 1 && ms <= 9) {
    		ms = "00" + ms;
    	} else if (ms >= 10 && ms <= 99) {
    		ms = "0" + ms;
    	}
    	var timestamp = ""+y + M + d + H + m + s + ms;
    	
    	/*webuploader  -------------------------------------*/
var dirName;
	var fmd5;
	var ppath;
	WebUploader.Uploader.register({
	    'before-send-file': 'preupload',  //整个文件上传前
	    "before-send":"beforeSend"       //每个分片上传前  
        //"after-send-file":"afterSendFile" //分片上传完毕
	}, {
	    preupload: function(file) {
	    	timestamp=timestamp+file.name.substring(file.name.lastIndexOf("."));
	        var me = this,
	            owner = this.owner,
	           // server = me.options.server,
	            deferred = WebUploader.Deferred();
	        var limit;
	        if(file.size<30*1024*1024){
	        	limit=file.size; 
	        }else{
	        	limit=30*1024*1024;
	        }
	        
	        owner.md5File(file,0,limit)

	        // 及时显示进度
	        .progress(function(percentage) {
	        	$('#' + file.id).find('p.state').text('正在检测文件...');
	        	$("#progresss").css("display", "block");
	        	$("#progress").html(parseInt(percentage * 100) + "%");
	        	$("#progress").css("width", parseInt(percentage * 100) + "%");
	            console.log('Percentage:', percentage);
	        })

	        // 完成
	        .then(function(value) {
	        	//dirName=value;
	        	fmd5=value;
	        	
	        	// 与服务安验证
	            $.ajax("/cbweb/demandprogram/filecheck.html", {
	                dataType: 'json',
	                data: {
	                    md5:value,
	                    zmtype:2
	                },
	                success: function( response ) {
	                	ppath=response.savePath;
	                	dirName=response.savePath+fmd5;
	                	me.options.formData.guid=dirName;
	                    // 如果验证已经上传过
	                    if ( response.exist ) {
	                        owner.skipFile( file );

	                        console.log('文件重复，已跳过');
	                    }
                       //alert("1122");
	                    // 介绍此promise, webuploader接着往下走。
	                    deferred.resolve();
	                }
	                
	            });
	        	
	        });
	       //alert("ddddddddddd");
	        return deferred.promise();
	    },
	    beforeSend:function(block){
	    	var me = this,
            owner = this.owner,
            server = me.options.server,
	    	deferred = WebUploader.Deferred();
	    	var chunkFile = block.blob;
            var file = block.file;
            var chunk = block.chunk;         //当前分块下标 
            var chunks = block.chunks;       //文件总分片数
            var start = block.start;
            var end = block.end;
            var total = block.total;
             
         // 与服务安验证
            $.ajax("/cbweb/demandprogram/checkqiepian.html", {
                dataType: 'json',
                data: {
                	dirName:dirName,
                    chunk: chunk      
                },
                success: function( response ) {
                    // 如果验证已经上传过
                    if (response.exist) {
                    	//验证md5
            owner.md5File( chunkFile )

	        // 及时显示进度
	        .progress(function(percentage) {
	            console.log('Percentage:', percentage);
	        })

	        // 完成
	        .then(function(chunkMd5) {
	        	// 与服务安验证
                $.ajax("/cbweb/demandprogram/checkqiepians.html", {
                    dataType: 'json',
                    data: {
                    	fname:timestamp,
                    	dirName:dirName,
                    	savepath:ppath,
                    	fmd5:fmd5,
                        md5: chunkMd5,
                        chunk: chunk      
                    },
                    success: function( response ) {
                        // 如果验证已经上传过
                        if (response.exist) {
                        	
                        	deferred.reject();
                        }else{
                        	deferred.resolve();
                        }   
                    }
                     
                });
                 
	        });
                    	
                    }else{
                    	
                    	deferred.resolve();
                    }   
                }
                 
            });
           // alert("11")
	        return deferred.promise();
	    }
	    
	});
	var uploader = WebUploader.create({
		// swf文件路径
		swf : '/cbweb/resource/js/webuploader/Uploader.swf',
		// 文件接收服务端。
		server : '/cbweb/UpFileServlet',
		// 选择文件的按钮。可选。
		// 内部根据当前运行是创建，可能是input元素，也可能是flash.
		pick : '#picker',
		// 上传本分片时预处理下一分片
		prepareNextFile : true,
		fileNumLimit:1,
		chunked : true, //分片处理
		chunkSize : 20 * 1024 * 1024, //每片100M  
		threads : 1,//上传并发数。允许同时最大上传进程数。

		// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
		resize : false,

	});

// 文件上传过程中创建进度条实时显示。
uploader.on('uploadProgress', function(file, percentage) {
$('#' + file.id).find('p.state').text('文件正在上传...');
//$("#progresss").css("display", "block");
$("#progress").html(parseInt(percentage * 100) + "%");
$("#progress").css("width", parseInt(percentage * 100) + "%");
});

//当有文件被添加进队列的时候
uploader.on('fileQueued', function(file) {
	$("#thelist").append(
			'<div id="' + file.id + '" class="item">'
					+ '<h4 class="info">' + file.name + '</h4>'
					+ '<p class="state">文件准备就绪...</p>' + '</div>');
});
var filejd;
uploader.on(
			'uploadSuccess',
			function(file) {
				$('#' + file.id).find('p.state').text('文件上传完成，正在提交数据，请勿关闭窗口！');
				$("#progress").html("1%");
				$("#progress").css("width","1%");
				filejd=file;
				sjd();
		
			});
function sjd(){
	//alert(filejd.size);
	$.post("/cbweb/demandprogram/UploadSuccessServlet.html",
			{
				"guid" : uploader.options.formData.guid,
				chunks : Math.ceil(filejd.size
						/ (20 * 1024 * 1024)),
				fileName : timestamp
			}, function(data,status) {
				data=JSON.parse(data);
				if(status=="success"){	
					
					if(data.status=="100"){
						document.getElementById("filepath").value=data.fileName;
						$('#' + filejd.id).find('p.state').text('文件上传成功！！！');
						$("#progress").html("100%");
						$("#progress").css("width", "100%");
						_submitFm();
					}else{
						$("#progress").html(data.status+"%");
						$("#progress").css("width", data.status+"%");
						setTimeout("sjd()",1000);
					}


				}
				
			});
	
}

uploader.on('uploadError', function(file) {
$('#' + file.id).find('p.state').text('上传出错');
});

uploader.on('uploadComplete', function(file) {
$('#' + file.id).find('.progress').fadeOut();
});
function auto_upload() {
	if ($('#tmpid').val() == null || $('#tmpid').val() == '') {
		alert("请先选择一个行业客户");
		return;
	}
	if ($('#name').val() == null || $('#name').val() == '') {
		alert("请填写视频名称");
		return;
	}
	//$('#' + file.id).find('p.state').text('文件正在上传...');
	uploader.upload();
}
    
    
    
    
      
        function myUploadMethod() {
        	var new_tmpid = $("#tmpid").val();
            if(new_tmpid=='' || new_tmpid==undefined || new_tmpid==null){
            	alert("请选择行业客户！");
            	return;
            }
            
            var purl=$("#purl").val();
            var puser=$("#puser").val();
            var ppsw=$("#ppsw").val();
            
        	document.getElementById("tipContent").style.display = "block";
        	
			
			$('#file_upload').uploadify(
					'settings',
					'uploader',
					'/cbweb/demandprogram/upload1.html?purl='+purl+'&puser='+puser+'&ppsw='+ppsw); // 数据处理url#######################
			$('#file_upload').uploadify('upload', '*');
		}
	/*
        var fx;
        var purl;
        var pport="21";
        var puser;
        var ppsw;
        $(document).ready(function() {
        	fx = document.getElementById("FtpX");  
        	var id = $("#tmpid").val();
        	if(id!=''){
        		confButton();
        	} else {
        	    purl = "122.229.29.70";
                pport = '21';
                puser = 'valueadd';
                ppsw = 'VA!2016.11.02';
                
               //// alert(purl + "--" + pport + "--" +puser+ "--" +ppsw);
                fx.SetFtpParam(purl, pport, puser, ppsw, "",1);
        	}
        }); 
        function setFtp() {
        	
            fx.SetFtpParam(purl, pport, puser, ppsw, "",1);
        }
        function setPath() {
            var temp = $("#path").val();
            var sum = fx.SetFtpParam(purl, pport, puser, ppsw, temp,1);
            $.messager.alert('提示', '设置成功', 'warning');

        }
        */
        
        
        
        
        
        var tmpid ;
        function confButton() {
    		var new_tmpid = $("#tmpid").val();
    		if(new_tmpid==tmpid){
    			return;
    		}
    		tmpid =new_tmpid;
    		$.ajax({
    			async : false,
    			url : '/cbweb/vchannel/ftp.html',
    			type : 'post',
    			data : {
    				tmpid : tmpid
    			},
    			dataType : "JSON",
    			success : function(result) {
    				if (result.success == false) {
    					$.messager.alert('提示', "当前行业客户没有开通虚拟频道，无法上传视频！", 'info', function() {
    						$.messager.progress('close');
    						purl='';
    						//setFtp();
    						//parent.$('#dlg').dialog('close');	
    						//parent.gotoSearch($('#easyui-treegrid'));
    					});
    				} else {
    					if (checkAjaxRequestValidity(result)) {
    						$.messager.progress('close');
    						purl=result.object.purl;
    						puser=result.object.puser;
    						ppsw=result.object.ppsw;
    						//setFtp();
    					}
    				}
    			}
    		});
    	}
    	function gotoconfButton() {
    		confButton();
    		$('#openselect').dialog('close');
    	}
        /***
        function SaveIt() {
        
            if (CheckIt()) {
                var fname = fx.GetFileName(0);
                var path = $("#ctl00_content_tbFolder").val();
                //alert('Save'); 
                var user = 'gaozhanglei';
                var id = $("#ctl00_content_hfId").val();
                var name = $("#ctl00_content_tbName").val();
                var desc = $("#ctl00_content_tbDesc").val();
                var remark = $("#ctl00_content_tbRemark").val();
                var stat = 0;
                var mids = $("#ctl00_content_hfMids").val();
                var epg = $("#ctl00_content_ddlEpg").val();

                var url = '/admin/Ajaxdo/AddIt.ashx?t=8&user=' + user + '&name=' + escape(name) +
                         '&desc=' + escape(desc) + '&remark=' + escape(remark) + 
                         '&id=' + id + '&stat=' + stat + '&epg=' + epg + '&path=' + escape(path) +
                         '&fname=' + escape(fname);
                $.post(url, function (msg) {
                    if (msg == 0) {
                        alert('成功!');
                        location = 'ProgramList.aspx?epg=' + epg;
                    }
                    else if (msg == 9) {
                        alert('c2接口调用出现错误!');
                    }
                    else {
                        alert(msg);
                    }
                });
            }
            
        }
        var regNum = /^\d*$/;
        function CheckIt() {

            if (!$("#ctl00_content_tbName").val()) {
                alert('请输入节目名称');
                return false;
            }
            var sort = $("#ctl00_content_tbSort").val();
            if (!sort) {
                $("#ctl00_content_tbSort").val('0')
            }
            else {
                if (!regNum.test(sort)) {
                    alert('无效的排序号');
                    return false;
                }
            }
            return true;
        }
        ***/
    </script>
	</body>
</html>
